import { defineStore, Store } from 'pinia'
import { IUserInfo } from '@/api/types/common'
import { getItem, setItem } from '@/utils/storage'
import { USER, APITEMPLATE, versionTemplate } from '@/utils/constants'

export interface State {
  count: number
  isCollapse: boolean
  apiTemplate: any
  versionTemplate: any
}

export const useStore = defineStore({
  id: 'store',
  state: () =>({
    count: 0,
    isCollapse: true,
    user: getItem<IUserInfo>(USER),
    apiTemplate: {},
    versionTemplate: {}
  }),
  getters: {
  },
  actions: {
    setIsCollapse (state: any, payload: any) {
      state.isCollapse = payload
    },
    setUser (state: any, payload: any) {
      state.user = payload
      setItem(USER, state.user)
    },
    setApiTemplate (state: any, payload: any) {
      state.apiTemplate = payload
      setItem(APITEMPLATE, state.apiTemplate)
    },
    setVersionTemplate (state: any, payload: any) {
      state.versionTemplate = payload
      setItem(versionTemplate, state.versionTemplate)
    }
  }
})


export default useStore